package ooo.reindeer.data.entity;

import io.netty.util.internal.ObjectUtil;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.concurrent.ConcurrentHashMap;

public class Option<T> {

    private static final ConcurrentHashMap<String, Option> pool = new ConcurrentHashMap<String, Option>();

    private String name;
    private String[] names;

    public String name() {
        if(names!=null){
            return names[0];
        }
        return name;
    }
    public String[] names(){
        return names;
    }


    public static <T extends Option> T valueOf(String name) {



        Option value = pool.get(name);
        if (value == null) {
            synchronized (pool) {
                value = pool.get(name);
                if (value == null) {
                    value = new Option<T>(name){};
                    pool.put(name, value);
                }
            }
        }

        return (T) value;

    }

    public Option(String name) {
        this.name = name;
        if(name.contains("?")){
            String [] temp=name.split("\\?");
            if(temp!=null&& temp.length!=0){
                names=temp;
            }
        }
    }

}

